package com.zhonghui.common.eshopMapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhonghui.common.eshopDomain.StoreCombination;
import com.zhonghui.common.eshopVo.StoreCombinationQueryVo;
import com.zhonghui.common.eshopVo.StoreProductQueryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StoreCombinationMapper extends CoreMapper<StoreCombination>{
    @Select({"SELECT c.id,c.effective_time as effectiveTime,c.info,c.image,c.people,c.price, s.sales as sales,c.title,c.unit_name as unitName,s.price as productPrice FROM store_combination c INNER JOIN store_product s ON s.id=c.product_id  WHERE c.is_show = 1 AND c.is_del = 0 AND c.start_time < now()  AND c.stop_time > now() ORDER BY c.sort desc,c.id desc"})
    List<StoreCombinationQueryVo> getCombList(Page page);

    <E extends IPage<StoreCombination>> E selectPage(E page, @Param("ew") Wrapper<StoreCombination> queryWrapper);

    @Select({"SELECT c.id,c.effective_time as effectiveTime,c.image,c.people,c.price,c.browse,c.description,c.image,c.images,c.info,c.product_id as productId,c.sales,c.start_time as startTime,c.stock,c.stop_time stopTime,c.title,c.unit_name as unitName,s.price as productPrice FROM store_combination c INNER JOIN store_product s ON s.id=c.product_id  WHERE c.is_show = 1 AND c.is_del = 0 AND c.id = #{id} "})
    StoreCombinationQueryVo getCombDetail(Long id);

    @Select({"SELECT c.id,c.image,c.price,c.title as storeName,c.is_show as isShow,c.cost,c.sales,c.stock,c.is_del as isDel FROM store_combination c  WHERE c.id = #{id} and c.is_del = 0 "})
    StoreProductQueryVo combinatiionInfo(Long id);

    @Update({"update store_combination set browse=browse+1 where id=#{productId}"})
    int incBrowseNum(@Param("productId") Long productId);
}

